/**
 * 
 */
package edu.cmu.cs.webapp.ioms.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

import edu.cmu.cs.webapp.ioms.models.PurchaseOrder;
import edu.cmu.cs.webapp.ioms.ui.dialogs.order.ViewOrderItemsDialog;

/**
 * @author Christian
 * 
 */
public class ViewCustomerViewAction implements IObjectActionDelegate,
		IViewActionDelegate {
	private PurchaseOrder order;
	private IWorkbenchPart target;
	private IViewPart view;

	/**
	 * 
	 */
	public ViewCustomerViewAction() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void init(IViewPart view) {
		this.view = view;

	}

	@Override
	public void run(IAction action) {
		if (order != null) {
			ViewOrderItemsDialog dlg = new ViewOrderItemsDialog(this.view
					.getSite().getShell(), order);
			dlg.open();
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		if (selection instanceof IStructuredSelection) {
			Object sel = ((IStructuredSelection) selection).getFirstElement();
			if (sel instanceof PurchaseOrder) {
				this.order = (PurchaseOrder) sel;
			}
		}
	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.target = targetPart;

	}

}
